// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Waterfall Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 57 : TYPE_WATERFALL

// Function declarations
reserve function Waterfall_DebugDraw
reserve function Waterfall_DebugSpawn

// Static Values
public value Waterfall_value36 = 0;

// Tables

function Waterfall_DebugDraw
	temp0 = object[0].value17
	temp0 -= Waterfall_value36
	DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
end function


function Waterfall_DebugSpawn
	temp0 = object[0].value17
	temp0 -= Waterfall_value36
	CreateTempObject(TypeName[Waterfall], temp0, object.xpos, object.ypos)
	object[tempObjectPos].direction = object.direction
	object[tempObjectPos].drawOrder = 4
	if object[tempObjectPos].propertyValue == 9
		object[tempObjectPos].frame = 9
	end if
end function


event ObjectMain
	if object.propertyValue == 9
		if object.state == 1
			temp0 = stage.waterLevel
			temp0 -= 16
			object.iypos = temp0
		end if
		object.animationTimer++
		if object.animationTimer == 6
			object.animationTimer = 0
			object.frame++
			if object.frame == 12
				object.frame = 9
			end if
		end if
	end if
end event


event ObjectDraw
	if object.propertyValue < 9
		DrawSpriteFX(object.propertyValue, FX_FLIP, object.xpos, object.ypos)
	else
		DrawSpriteFX(object.frame, FX_FLIP, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("LZ/Objects.gif")
	SpriteFrame(-5, -16, 13, 32, 191, 140)
	SpriteFrame(-10, -4, 22, 12, 61, 38)
	SpriteFrame(-6, -4, 14, 12, 117, 90)
	SpriteFrame(0, -4, 8, 12, 132, 90)
	SpriteFrame(-6, -4, 14, 12, 117, 103)
	SpriteFrame(0, -4, 8, 12, 132, 103)
	SpriteFrame(0, -4, 8, 12, 191, 76)
	SpriteFrame(-8, -16, 16, 32, 240, 223)
	SpriteFrame(-24, -8, 46, 16, 158, 173)
	SpriteFrame(-20, -16, 39, 32, 118, 161)
	SpriteFrame(-22, -12, 41, 28, 117, 194)
	SpriteFrame(-24, -16, 47, 32, 159, 190)
	foreach (TypeName[Waterfall], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].drawOrder = 4
		if object[arrayPos0].propertyValue == 9
			object[arrayPos0].frame = 9
		end if
	next
	temp0 = 0
	Waterfall_value36 = DebugMode_ObjCount
	while temp0 < 10
		SetTableValue(TypeName[Waterfall], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(Waterfall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(Waterfall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
